Skip to content

Test Shader compilation with WEBMIN flag#1638

Open
CedricGuillemet wants to merge 14 commits into
BabylonJS:masterfrom
CedricGuillemet:TestShaderCompilation
Open

Test Shader compilation with WEBMIN flag#1638
CedricGuillemet wants to merge 14 commits into
BabylonJS:masterfrom
CedricGuillemet:TestShaderCompilation

Conversation

@CedricGuillemet
Copy link
Copy Markdown
Collaborator

@CedricGuillemet CedricGuillemet commented Mar 19, 2026

Use a generated shader to check no mandatory glsl function missing in spirv-cross when using WEBMIN flag.

BabylonJS/SPIRV-Cross#10

Fix

UniformTypeChangeTraverser and MoveNonSamplerUniformsIntoStruct were also visiting whole layout(std140) uniform blocks (EbtBlock) and uniform Foo foo; struct instances (EbtStruct) and rewriting them to vec4, producing unnamed placeholder uniforms in the spirv-cross output and a Identifier can't be empty. assert in bgfx. Both traversers are now restricted to scalar/vector basic types (Float/Int/Uint/Bool). CollectNonSamplerUniforms also throws early if a uniform name is empty so future regressions surface in the compiler instead of deep in bgfx.

@CedricGuillemet CedricGuillemet changed the title Test Shader compilation Test Shader compilation wtih WEBMIN flag Mar 19, 2026
CedricGuillemet and others added 3 commits April 17, 2026 14:24
…nto TestShaderCompilation

# Conflicts:
#	Apps/UnitTests/CMakeLists.txt
…raversers.

UniformTypeChangeTraverser and MoveNonSamplerUniformsIntoStruct only
excluded samplers and matrices, so they happily visited the symbols
representing whole `layout(std140) uniform` blocks (EbtBlock) and
`uniform Foo foo;` struct instances (EbtStruct), rewriting them to
vec4. Once that happened, spirv-cross emitted unnamed placeholder
uniforms (e.g. `uniform vec4 _1195;`) and the matrix multiplies
collapsed to scalar nonsense, then bgfx asserted on the empty uniform
name (`Identifier can't be empty.`).

Restrict both traversers to scalar/vector basic types (Float/Int/Uint/
Bool) so blocks and structs are left intact. Also throw early in
CollectNonSamplerUniforms if a uniform name is empty, so any future
regression surfaces in the compiler instead of as a deep bgfx assert.

Add a TODO in CMakeLists.txt to point SPIRV-Cross back to the upstream
BabylonJS fork once the corresponding PR there is merged.
@CedricGuillemet CedricGuillemet marked this pull request as ready for review May 12, 2026 14:39
Copilot AI review requested due to automatic review settings May 12, 2026 14:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a comprehensive shader cross-compilation unit test and tightens shader AST traversers to avoid incorrectly rewriting UBO blocks and struct uniforms, preventing empty/placeholder uniform identifiers from reaching bgfx.

Changes:

  • Restrict uniform traversers to basic scalar/vector types to avoid visiting EbtBlock/EbtStruct uniforms.
  • Add a UnitTests scenario that compiles a large WebGL2 GLSL shader to exercise SPIRV-Cross with the WEBMIN flag.
  • Update the fetched SPIRV-Cross dependency to a specific fork/commit and add an early compiler-side guard for empty uniform names.

Reviewed changes

Copilot reviewed 7 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Plugins/ShaderCompiler/Source/ShaderCompilerTraversers.cpp Limits traversers to avoid rewriting UBO blocks/struct uniforms.
Plugins/ShaderCompiler/Source/ShaderCompilerCommon.cpp Adds early failure when a reflected uniform name is empty.
CMakeLists.txt Changes SPIRV-Cross FetchContent repository/commit.
Apps/UnitTests/Source/Tests.Shaders.Cross.cpp Adds a new runtime-backed shader compilation unit test.
Apps/UnitTests/JavaScript/webpack.config.js Adds a new webpack entry for the shader cross test.
Apps/UnitTests/JavaScript/src/tests.shaders.cross.ts New “comprehensive GLSL” test script.
Apps/UnitTests/JavaScript/dist/tests.shaders.cross.js Built webpack output for the new test script.
Apps/UnitTests/JavaScript/dist/tests.shaderCache.basicScene.js Updated built output (webpack bootstrap changes).
Apps/UnitTests/CMakeLists.txt Includes new JS asset and C++ test source in UnitTests target.

Comment on lines +312 to 320
// We only care about loose scalar/vector uniforms. Excluding matrices, samplers,
// UBO blocks (EbtBlock) and uniform struct instances (EbtStruct) prevents the
// traverser from rewriting whole blocks/structs to vec4, which destroys their
// member layout and member names.
const auto basic = type.getBasicType();
if (type.getQualifier().isUniformOrBuffer()
&& !type.isMatrix()
&& (basic == EbtFloat || basic == EbtInt || basic == EbtUint || basic == EbtBool))
{
Comment thread CMakeLists.txt Outdated
Comment thread Plugins/ShaderCompiler/Source/ShaderCompilerCommon.cpp
@CedricGuillemet CedricGuillemet changed the title Test Shader compilation wtih WEBMIN flag Test Shader compilation with WEBMIN flag May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants